package com.xbell.app.sys.controller;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="modelAttribute")
public class ModelAttributeController {
	
	private String myAttr = "123";
	
	public String getMyAttr() {
		return this.myAttr;
	}
	
	public void setMyAttr(String a) {
		this.myAttr  = a;
	}

	@ModelAttribute
	public void attr1(@RequestParam String abc, Model model) {
        model.addAttribute("attr1", abc);
	}
	
	@ModelAttribute
	public ModelAttributeController attr2() {
		ModelAttributeController m =  new ModelAttributeController();
		return m;
	}
	
	@RequestMapping(value="mv1")
	public String mv1(@ModelAttribute("attr3") String attr3,@ModelAttribute(name = "mc2") ModelAttributeController mc,ModelMap mm,int c) {
		return "modelAttribute/mv1";
	}
	
	@RequestMapping(value="mv2")
	public ModelAndView mv2() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("modelAttribute/mv1");
		return mv;
	}
	
	@InitBinder
	public void initBinder(WebDataBinder wdb) {
		LoggerFactory.getLogger(getClass()).info("init Binder");
	}
}
